<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateArticles extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('articles', ['comment' => '文章']);
        $table
            ->addColumn('article_type_id', 'integer',array('limit' => 30,'default' => 0,'comment' => '文章分类id'))
            ->addColumn('create_id', 'integer',array('limit' => 30, 'default' => 0,'comment' => '创建文章的用户id'))
            ->addColumn('title', 'string',array('limit' => 250,'null' => true,'comment' => '文章标题'))
            ->addColumn('path', 'string', array('limit' => 250,'null' => true, 'comment' => '封面'))
            ->addColumn('is_hot', 'boolean', array('limit' => 1, 'default' => 0, 'comment' => '是否热门(0,1 否and是)'))
            ->addColumn('desc', 'string', array('limit' => 330, 'null' => true, 'comment' => '文章摘要'))
            ->addColumn('sort', 'integer', array('limit' => 30, 'default' => 1, 'comment' => '排序'))
            ->addColumn('status', 'boolean',array('limit' => 1, 'default' => 1, 'comment' => '状态(开启or关闭,1or0)'))
            ->addColumn('content', 'text', array('null' => true, 'comment' => '描述'))
            ->addTimestamps()
            ->addSoftDelete()
            ->create();



        $table = $this->table('article_type', ['comment' => '文章类别']);
        $table
            ->addColumn('name', 'string',array('limit' => 50,'null' => true,'comment' => '分类名字'))
            ->addColumn('status', 'boolean',array('limit' => 1, 'default' => 1, 'comment' => '状态(开启or关闭,1or0)'))
            ->addTimestamps()
            ->addSoftDelete()
            ->create();
    }
}
